﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TestWeb
{
    public partial class Register1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            var txtUserName = TextBox1.Text.Trim();
            var txtUserPwd = TextBox2.Text.Trim();
            var txtUserPwd2 = TextBox3.Text.Trim();


            string sql = "select * from Users where Username='" + txtUserName + "'";
            DataTable table = DbHelper.GetDataTable(sql);

            if (txtUserPwd == txtUserPwd2)
            {
                if (table.Rows.Count == 1)
                {
                    Label4.Text = "账号已注册";
                    Label4.Visible = true;
                }
                else
                {
                    sql = "insert into Users(Username,Passwords) values('" + txtUserName + "','" + txtUserPwd + "')";
                    DbHelper.Modification(sql);
                    Response.Redirect("Login.aspx");
                }
            }
            else
            {
                Label4.Text = "两次密码不正确";
                Label4.Visible = true;
            }

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }
    }
}